// pages/index/nearbyTeams/doctorDetail/doctorDetail.js
import request from '../../../../utils/request'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    team1:{},
    institution:{},
    doctorInfo: {
      
    },
    jigou:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if (options.id) {
      this.getDoctorDetail(options.id);
      this.getTeamDetail(options.id);
    }
  },

  getDoctorDetail(id) {
    request({
      url: `system/doctor/${id}`,
      method: 'GET',
      success: (res) => {
        console.log(res.data.data)
        if (res.data.code === 200) {
          this.setData({
            doctorInfo: res.data.data
          });
        }
      }
    });
  },
  
  getTeamDetail(id) {
    request({
      url: 'system/team/'+id,
      method: 'GET',
      success: (result) => {
        this.setData({
          team1:result.data.data
        })
        request({
          url: 'system/institution/'+result.data.data.institutionid,
          method: 'GET',
          success: (res) => {
            this.setData({
              institution:res.data.data
            })
          },
          fail: (err) => {},
          complete: (res) => {},
        })
      },
      fail: (err) => {},
      complete: (res) => {},
    })
  },
  onInstitutionTap() {
    let id  = this.data.institution.id;
    wx.navigateTo({
      url: `/pages/index/nearbyInstitutions/institutionDetail/institutionDetail?id=`+id
    });
  },

  onTeamTap() {
    let id = this.data.doctorInfo.id;
    wx.navigateTo({
      url: `/pages/index/nearbyTeams/teamDetail/teamDetail?id=`+id
    });
  },

  onSignDoctor() {
    wx.showModal({
      title: '提示',
      content: '确定要签约该医生吗？',
      success: (res) => {
        if (res.confirm) {
          let id=this.data.doctorInfo.id
          wx.navigateTo({
            url: '/pages/index/nearbyTeams/shenqingqianyue/shenqingqianyue?id='+id,
          })
        }
      }
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})